package com.tarena.lbs.activity.rpc;

import com.tarena.lbs.activity.api.ActivityApi;
import com.tarena.lbs.activity.api.pojo.ActivityDto;
import com.tarena.lbs.activity.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@DubboService
public class ActivityApiImpl implements ActivityApi {

    @Autowired
    private ActivityService activityService;

    @Override
    public Boolean activityVisible(Integer userId, Integer activityId) {
        // 简化：默认返回可见（可根据用户人群与活动目标人群进一步实现）
        return true;
    }

    @Override
    public ActivityDto getActivityById(Integer activityId) {
       try {
           var vo = activityService.detail(activityId);
           if (vo == null) return null;
           ActivityDto dto = new ActivityDto();
           dto.setId(vo.getId());
           dto.setActivityName(vo.getActivityName());
           dto.setStatus(vo.getStatus());
           dto.setEnableStatus(vo.getEnableStatus());
           dto.setActivityType(vo.getActivityType());
           dto.setChannelType(vo.getChannelType());
           dto.setStartDate(vo.getStartDate());
           dto.setEndDate(vo.getEndDate());
           dto.setDescribes(vo.getDescribes());
           dto.setImgIds(vo.getImgIds());
           dto.setShopIds(vo.getShopIds());
           dto.setTargetCustomer(vo.getTargetCustomer());
           dto.setActivityTarget(vo.getActivityTarget());
           dto.setDeliveryChannel(vo.getDeliveryChannel());
           dto.setRewardType(vo.getRewardType());
           dto.setRewardCouponId(vo.getRewardCouponId());
           dto.setShareProfile(vo.getShareProfile());
           dto.setShareUrl(vo.getShareUrl());
           dto.setActivityJson(vo.getActivityJson());
           dto.setMarketingType(vo.getMarketingType());
           dto.setBusinessId(vo.getBusinessId());
           dto.setCreateAt(vo.getCreateAt());
           dto.setUpdateAt(vo.getUpdateAt());
           return dto;
       } catch (com.tarena.lbs.base.protocol.exception.BusinessException e) {
           return null;
       }
    }
}
